#include <stdio.h>

void moveZeroes(int* nums, int numsSize) 
{
    int i = 0; 
    // 指向当前非零元素应该放置的位置
    for (int j = 0; j < numsSize; j++) 
    {
        if (nums[j] != 0) 
        {
            nums[i++] = nums[j];
        }
    }
    // 将剩余的位置填为零
    for (i; i < numsSize; i++) 
    {
        nums[i] = 0;
    }
}


int main(int argc, char const *argv[])
{
    int arr[] = {0,1,0,3,12};

    int len = sizeof(arr)/sizeof(int);

    for(int i = 0; i < len; i++)
    {
        printf("%d ",arr[i]);
    }
    printf("\n");


    moveZeroes(arr,len);

    for(int i = 0; i < len; i++)
    {
        printf("%d ",arr[i]);
    }
    printf("\n");

    return 0;
}
